package com.example.toy.core.utils;

import java.util.Objects;

/**
 * Asserts
 *
 * @author shenbing
 * @date 2021/12/21
 */
public class Asserts {

  public static void shouldTrue(String msg, boolean b) {
    if (!b) {
      throw new IllegalArgumentException(msg);
    }
  }

  public static void shouldFalse(String msg, boolean b) {
    if (b) {
      throw new IllegalArgumentException(msg);
    }
  }

  public static void shouldEquals(String msg, Object o1, Object o2) {
    if (!Objects.equals(o1, o2)) {
      throw new IllegalArgumentException(msg);
    }
  }

  public static void shouldNotEquals(String msg, Object o1, Object o2) {
    if (Objects.equals(o1, o2)) {
      throw new IllegalArgumentException(msg);
    }
  }

  public static void shouldBlank(String msg, String str) {
    if (str != null && !str.trim().isEmpty()) {
      throw new IllegalArgumentException(msg);
    }
  }

  public static void shouldNotBlank(String msg, String str) {
    if (str == null || str.trim().isEmpty()) {
      throw new IllegalArgumentException(msg);
    }
  }

  public static void shouldNull(String msg, Object obj) {
    if (obj != null) {
      throw new IllegalArgumentException(msg);
    }
  }

  public static void shouldNotNull(String msg, Object obj) {
    if (obj == null) {
      throw new IllegalArgumentException(msg);
    }
  }

  public static void shouldSame(String msg, Object o1, Object o2) {
    if (o1 != o2) {
      throw new IllegalArgumentException(msg);
    }
  }

  public static void shouldNotSame(String msg, Object o1, Object o2) {
    if (o1 == o2) {
      throw new IllegalArgumentException(msg);
    }
  }
}
